<template>
    <div class="supplier_detail">
        <van-nav-bar title="供应商详情" right-text="编辑" left-arrow @click-left="router.back()" @click-right="onClickRight">
            <template #right>
                <van-image :src="bianji" class="bianji" />
                编辑
            </template>
        </van-nav-bar>
        <div class="content">
            <div class="supplier_detail_top">
                <div class="supplierName">{{ detailInfo.supplierName }}</div>
                <div class="nums">
                    <div class="nums_div">
                        <div class="nums_number">{{ detailInfo.productsCount }}</div>
                        <div class="nums_name">货品总数</div>
                    </div>
                    <div class="nums_div">
                        <div class="nums_number">{{ detailInfo.productsShopping }}</div>
                        <div class="nums_name">上架总数</div>
                    </div>
                    <div class="nums_div">
                        <div class="nums_number">{{ detailInfo.productsOpt }}</div>
                        <div class="nums_name">选品数</div>
                    </div>
                </div>
            </div>
            <div class="supplier_detail_content">
                <div class="supplier_detail_content_div supplier_detail_content_divorder">
                    <div class="label">商家类型</div>
                    <div class="value">{{ detailInfo.supplierType }}</div>
                </div>
                <div class="supplier_detail_content_div supplier_detail_content_divorder">
                    <div class="label">厂家地址</div>
                    <div class="value">{{ detailInfo.addr }}</div>
                </div>
                <div class="supplier_detail_content_div supplier_detail_content_divorder">
                    <div class="label">详细地址</div>
                    <div class="value">{{ detailInfo.address }}</div>
                </div>
                <div class="supplier_detail_content_div supplier_detail_content_divorder">
                    <div class="label">联系人</div>
                    <div class="value">{{ detailInfo.contactName }}</div>
                </div>
                <div class="supplier_detail_content_div supplier_detail_content_divorder">
                    <div class="label">手机号</div>
                    <div class="value">{{ detailInfo.phone }}</div>
                </div>
                <div class="supplier_detail_content_div supplier_detail_content_divorder">
                    <div class="label">统一社会信用代码</div>
                    <div class="value">{{ detailInfo.companyCode }}</div>
                </div>
                <div class="supplier_detail_content_div supplier_detail_content_divorder">
                    <div class="label">营业执照所在地</div>
                    <div class="value">{{ detailInfo.businessAddr }}</div>
                </div>
                <div class="supplier_detail_content_div supplier_detail_content_divorder">
                    <div class="label">营业执照有效期</div>
                    <div class="value">{{ detailInfo.businessDate }}</div>
                </div>
                <div class="supplier_detail_content_div supplier_detail_content_divorder">
                    <div class="label">营业执照</div>
                    <div class="value">
                        <IsImgPdf :url="detailInfo.businessImages" width="32" height="32" />
                    </div>
                </div>
                <div class="supplier_detail_content_div supplier_detail_content_divorder">
                    <div class="label">店铺id</div>
                    <div class="value">{{ detailInfo.storeId }}</div>
                </div>
                <div class="supplier_detail_content_div supplier_detail_content_divorder">
                    <div class="label">店铺类型</div>
                    <div class="value">{{ detailInfo.storeType }}</div>
                </div>
                <div class="supplier_detail_content_div supplier_detail_content_divorder">
                    <div class="label">店铺评分</div>
                    <div class="value">{{ detailInfo.storeGrade }}</div>
                </div>
                <div class="supplier_detail_content_div supplier_detail_content_divorder">
                    <div class="label">其他资质</div>
                    <div class="value">
                        <IsImgPdf v-if="detailInfo.otherImages?.length" v-for="(item, index) in detailInfo.otherImages"
                            width="32" height="32" :key="index" :url="item" />
                        <IsImgPdf v-else url="" width="32" height="32" />
                    </div>
                </div>
            </div>
            <div class="title">合同信息</div>
            <div class="supplier_detail_contract">
                <div class="supplier_detail_content_div supplier_detail_content_divorder"
                    @click="contract('供销合同', sellId)">
                    <div class="label">供销合同</div>
                    <div class="value" :style="{
                        color: sellId.length > 1 ? '#19D11B' : '#B8BECA',
                    }">
                        {{ sellId.length > 1 ? "已签署" : "未签署"
                        }}<van-icon name="arrow" color="#B8BECA" />
                    </div>
                </div>
                <div class="supplier_detail_content_div" @click="contract('保证金协议', marginId)">
                    <div class="label">保证金协议</div>
                    <div class="value" :style="{
                        color: marginId.length > 1 ? '#19D11B' : '#B8BECA'
                    }">
                        {{ marginId.length > 1 ? "已签署" : "未签署"
                        }}<van-icon name="arrow" color="#B8BECA" />
                    </div>
                </div>
                <div class="supplier_detail_content_div" @click="contract('包销合同', packageStatusId)"
                    v-if="!inventStaffFlag">
                    <div class="label">包销合同</div>
                    <div class="value" :style="{
                        color: packageStatusId.length > 1 ? '#19D11B' : '#B8BECA'
                    }">
                        {{ packageStatusId.length > 1 ? "已签署" : "未签署"
                        }}<van-icon name="arrow" color="#B8BECA" />
                    </div>
                </div>
                <div class="supplier_detail_content_div" @click="contract('补充协议', supplementaryId)">
                    <div class="label">补充协议</div>
                    <div class="value" :style="{
                        color: supplementaryId.length > 1 ? '#19D11B' : '#B8BECA'
                    }">
                        {{ supplementaryId.length > 1 ? "已签署" : "未签署"
                        }}<van-icon name="arrow" color="#B8BECA" />
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { computed, ref } from "vue";
import { useRoute, useRouter } from "vue-router";
import {
    hmSupplierList,
    getcontractList,
    getbrandList,
} from "@/api/supplierList/index";
import IsImgPdf from '@/components/isImgPdf/index.vue'
const bianji = new URL("@/assets/porduct/bianji.png", import.meta.url).href;
import { getEnvValue } from "@/utils/index";
import { userStore } from "@/store/user";
const route = useRoute();
const router = useRouter();
const detailInfo = ref<any>({});
const user = userStore();
// 是否为研发部新增品牌
const inventStaffFlag = computed(() => {
    return user.user.indexOf('invent') == -1
})
// 供销合同id
const sellId = ref('');
// 破价合同id
const discountStatusId = ref('');
// 保证金协议id
const marginId = ref('')
// 补充协议id
const supplementaryId = ref('')
// 包销合同id
const packageStatusId = ref('')
const brandList = ref<any[]>([]);
/** 商品id */
const uniquekey = computed(() => {
    return route.params.id;
});
/** 获取详情 */
const getDetail = async () => {
    const res = await hmSupplierList({ id: uniquekey.value as any });
    detailInfo.value = res.rows[0];
    if (res.rows[0].businessImage) {
        detailInfo.value.businessImages = getEnvValue("VITE_APP_PIC_URL") + res.rows[0].businessImage
    }
    if (res.rows[0].otherImage) {
        let arr = []
        res.rows[0].otherImage.split(',').forEach(item => {
            arr.push(getEnvValue("VITE_APP_PIC_URL") + item)
        })
        detailInfo.value.otherImages = arr
    }
};
getDetail();
/** 获取品牌列表 */
const getbrand = async () => {
    const res = await getbrandList({ supplierId: uniquekey.value });
    brandList.value = res.rows;
};
getbrand();
/** 获取合同列表 */
const getContract = async () => {
    const res = await getcontractList({
        supplierId: uniquekey.value,
        contractType: "供销合同",
    });
    sellId.value = res.rows[0] ? res.rows[0].id : "";
    const response = await getcontractList({
        supplierId: uniquekey.value,
        contractType: "破价合同",
    });
    discountStatusId.value = response.rows[0] ? response.rows[0].id : "";
    const responseMargin = await getcontractList({
        supplierId: uniquekey.value,
        contractType: "保证金协议",
    });
    marginId.value = responseMargin.rows[0] ? responseMargin.rows[0].id : "";
    const ressupplementaryId = await getcontractList({
        supplierId: uniquekey.value,
        contractType: "补充协议",
    });
    supplementaryId.value = ressupplementaryId.rows[0] ? ressupplementaryId.rows[0].id : "";
    const packageStatusIdList = await getcontractList({
        supplierId: uniquekey.value,
        contractType: "包销合同",
    });
    packageStatusId.value = packageStatusIdList.rows[0] ? packageStatusIdList.rows[0].id : "";
};
getContract();
const onClickRight = () => {
    router.push(`/researchEditSupplier/${uniquekey.value}`);
};
/** 合同跳转 */
const contract = async (type, status) => {
    if (status) {
        if (type == "供销合同") {
            router.push({
                path: "/researchContract",
                query: {
                    detailInfo: JSON.stringify(detailInfo.value),
                    id: sellId.value,
                    type: "供销合同",
                },
            });
        } else if (type == "破价合同") {
            router.push({
                path: "/researchContract",
                query: {
                    detailInfo: JSON.stringify(detailInfo.value),
                    id: discountStatusId.value,
                    type: "破价合同",
                },
            });
        } else if (type == '保证金协议') {
            router.push({
                path: "/researchContract",
                query: {
                    detailInfo: JSON.stringify(detailInfo.value),
                    id: marginId.value,
                    type: "保证金协议",
                },
            });
        } else if (type == '补充协议') {
            router.push({
                path: "/researchContract",
                query: {
                    detailInfo: JSON.stringify(detailInfo.value),
                    id: supplementaryId.value,
                    type: "补充协议",
                },
            });
        } else if (type == '包销合同') {
            router.push({
                path: "/researchContract",
                query: {
                    detailInfo: JSON.stringify(detailInfo.value),
                    id: packageStatusId.value,
                    type: "包销合同",
                },
            });
        }
    }
};
</script>
<style lang="less" scoped>
.supplier_detail {
    width: 100%;
    height: calc(100vh - 44px);
    background-color: #f6faff;
    box-sizing: border-box;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    justify-content: center;

    .content {
        width: 100%;
        height: calc(100% - 46px);
        overflow-y: scroll;
        overflow-x: hidden;
        box-sizing: border-box;
        margin-top: 46px;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: center;
        align-content: flex-start;
    }

    .bianji {
        width: 12px;
        height: 12px;
        margin-right: 3px;
    }

    :deep(.van-nav-bar__right) {
        color: #0094ff;
        font-size: 13px;
        display: flex;
        align-items: center;
    }

    .supplier_detail_top {
        width: 98%;
        height: 20vh;
        padding: 20px;
        // margin-top: 46px;
        box-sizing: border-box;
        border-radius: 3px;
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        background: linear-gradient(180deg, #ddf0fe 0%, #ffffff 100%);

        .supplierName {
            width: 100%;
            height: 40%;
            font-size: 17px;
            display: flex;
            justify-content: center;
            align-items: center;
            font-weight: bold;
        }

        .nums {
            width: 80%;
            height: 40%;
            display: flex;
            align-items: center;
            font-size: 14px;
            justify-content: space-between;
            margin-left: 10%;

            .nums_div {
                text-align: center;

                .nums_name {
                    color: #b8beca;
                }

                .nums_number {
                    font-size: 20px;
                    line-height: 35px;
                    font-weight: bold;
                }
            }

            .line {
                height: 100%;
                border: 1px solid #bbbbbb;
            }
        }
    }

    .supplier_detail_content {
        width: 98%;
        // height: 20vh;
        margin-top: 5px;
        background-color: #fff;
        box-sizing: border-box;
        border-radius: 3px;
        font-size: 13px;

        .supplier_detail_content_divorder {
            border-bottom: 1px solid #fafaff;
        }

        .supplier_detail_content_div {
            min-height: 35px;
            // height: 25%;
            width: 90%;
            margin-left: 5%;
            display: flex;
            justify-content: space-between;
            align-items: center;

            :deep(.van-icon) {
                margin-left: 0% !important;
            }

            .label {
                min-width: 55px;
            }

            .van-image {
                width: 32px;
                height: 32px;
            }

            .value {
                color: #b8beca;
                max-width: calc(100% - 85px);
                display: flex;
                justify-content: right;
                word-break: break-all;
            }
        }
    }

    .title {
        width: 100%;
        padding: 10px 20px;
    }

    .titles {
        width: 100%;
        padding: 10px 20px;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .supplier_detail_contract {
        width: 98%;
        // height: 10vh;
        background-color: #fff;
        box-sizing: border-box;
        border-radius: 3px;
        font-size: 13px;

        .supplier_detail_content_divs {
            .value {
                min-width: 60px;
            }
        }

        .supplier_detail_content_div {
            min-height: 35px;
            // height: 50%;
            width: 90%;
            margin-left: 5%;
            display: flex;
            justify-content: space-between;
            align-items: center;

            .value {
                color: #b8beca;
            }
        }
    }

    :deep(.van-nav-bar) {
        background-color: #1466ff;
        height: 46px !important;
        width: 100%;
        position: fixed;
    }

    :deep(.van-nav-bar__title) {
        color: #000;
    }

    :deep(.van-nav-bar__text) {
        color: #0094ff;
    }

    :deep(.van-icon) {
        margin-left: 5px;
    }
}
</style>
